package com.wao.product.service.mapper;

import com.wao.product.domain.*;
import com.wao.product.service.dto.AttributeDTO;

import org.mapstruct.*;

/**
 * Mapper for the entity Attribute and its DTO AttributeDTO.
 */
@Mapper(componentModel = "spring", uses = {ProductMapper.class, ProductSkuMapper.class, PropertyMapper.class, ValueMapper.class, })
public interface AttributeMapper extends EntityMapper <AttributeDTO, Attribute> {

    @Mapping(source = "product.id", target = "productId")
    @Mapping(source = "product.name", target = "productName")

    @Mapping(source = "productSku.id", target = "productSkuId")
    @Mapping(source = "productSku.name", target = "productSkuName")

    @Mapping(source = "property.id", target = "propertyId")
    @Mapping(source = "property.name", target = "propertyName")

    @Mapping(source = "value.id", target = "valueId")
    @Mapping(source = "value.name", target = "valueName")
    AttributeDTO toDto(Attribute attribute); 

    @Mapping(source = "productId", target = "product")

    @Mapping(source = "productSkuId", target = "productSku")

    @Mapping(source = "propertyId", target = "property")

    @Mapping(source = "valueId", target = "value")
    Attribute toEntity(AttributeDTO attributeDTO); 
    default Attribute fromId(Long id) {
        if (id == null) {
            return null;
        }
        Attribute attribute = new Attribute();
        attribute.setId(id);
        return attribute;
    }
}
